package project.model;

import java.io.Serializable;
import java.sql.ResultSet;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import models.util.MySqlDataAccessHelper;

public class PrComment implements Serializable {

	private static final long serialVersionUID = -6806536592086465601L;

	private String idComment;
	private String idTestProject;
	private String idEmployee;
	private String comment;
	private Date dateComment;
	private String colorText;
	
	private String employeeName;
	private String employeeName_;
	private String displayDate;
	DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss aaa");
	private String db="admin";
	
	private String idLogChange=null;
	private String commentview;
	
	private String nameEployee;
	
	
	public String getCommentview() {
		commentview=comment;
		int index = comment.indexOf("-%$#@!-");
		if(index > 0){
			commentview = comment.substring(0,index);
		}
		return commentview;
	}

	public void setCommentview(String commentview) {
		this.commentview = commentview;
	}

	public String getColorText() {
		int index = comment.indexOf("-%$#@!-");
		
		if(index > 0){
			colorText = comment.substring(index + 7, comment.length());
		}else{
			colorText = "#424242";
		}
		return colorText;
	}

	public void setColorText(String colorText) {
		this.colorText = colorText;
	}

	
	public String getIdLogChange(String dbc) {
		String s=null;
		if(dbc!=null){
			MySqlDataAccessHelper mysql =new MySqlDataAccessHelper();
			try{
				mysql.open(dbc);
				String sql="";
				ResultSet rs= mysql.executeQuery(sql);
				while(rs.next()){
					if(s.equals(null)){
						s=rs.getString("IDLogChange");
					}else{
						s+=","+rs.getString("IDLogChange");
					}
				}
				
				if(s.equals(null)==false){
					idLogChange=s;
				}
				
				rs.close();
			}catch(Exception e){
				e.printStackTrace();
			}finally{
				mysql.close();
			}
		}
		return idLogChange;
	}

	public void setIdLogChange(String idLogChange) {
		this.idLogChange = idLogChange;
	}

	public String getDb() {
		return db;
	}

	public void setDb(String db) {
		this.db = db;
	}

	public PrComment(){		
	}
	
	public PrComment(String idComment, String idTestProject, String idEmployee, String comment, Date dateComment, String employeeName) {
		this.idComment = idComment;
		this.idTestProject = idTestProject;
		this.idEmployee = idEmployee;
		this.comment = comment;
		this.dateComment = dateComment;
		this.employeeName = employeeName;
	}

	public String getIdComment() {
		return idComment;
	}

	public void setIdComment(String idComment) {
		this.idComment = idComment;
	}

	public String getIdTestProject() {
		return idTestProject;
	}

	public void setIdTestProject(String idTestProject) {
		this.idTestProject = idTestProject;
	}

	public String getIdEmployee() {
		return idEmployee;
	}

	public void setIdEmployee(String idEmployee) {
		this.idEmployee = idEmployee;
	}

	public String getComment() {
		return comment;
	}

	public void setComment(String comment) {
		this.comment = comment;
	}

	public Date getDateComment() {
		return dateComment;
	}

	public void setDateComment(Date dateComment) {
		this.dateComment = dateComment;
	}

	public void setEmployeeName(String employeeName) {
		
		this.employeeName = employeeName;
	}

	public String getEmployeeName() {
		if(this.db!=null){
			MySqlDataAccessHelper mysql=new MySqlDataAccessHelper();
			try{
				mysql.open(this.db);
				String sql="select FullName " +
						"from employee " +
						"where IDEmployee='"+this.idEmployee+"'";
				ResultSet rs=mysql.executeQuery(sql);
				if(rs.next()){
					employeeName=rs.getString("FullName");
				}
				rs.close();
			}catch(Exception e){
				e.printStackTrace();
			}finally{
				mysql.close();
			}
		}
		
		return employeeName;
	}

	public void setDisplayDate(String displayDate) {
		this.displayDate = displayDate;
	}

	public String getDisplayDate() {
		if(dateComment!=null){
			displayDate = format.format(dateComment);
		}		
		return displayDate;
	}
	
	public String getDisplayDate1() {
//		if(dateComment!=null){
//			displayDate = format.format(dateComment);
//		}		
		return displayDate;
	}
	
	public void setDisplayDate1(String displayDate) {
		this.displayDate = displayDate;
	}

	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return "+ "+this.comment+" ("+this.dateComment+")";
	}

	public void setNameEployee(String nameEployee) {
		this.nameEployee = nameEployee;
	}

	public String getNameEployee() {
		return nameEployee;
	}

	public String getEmployeeName_() {
		return employeeName_;
	}

	public void setEmployeeName_(String employeeName_) {
		this.employeeName_ = employeeName_;
	}

}
